package cn.learn.server.persistence;

import cn.learn.server.Record;
import cn.learn.server.jute.InputArchive;
import cn.learn.server.jute.OutputArchive;

import java.io.IOException;

public class FileHeader implements Record {
    private int magic;
    private int version;
    private long dbid;

    public FileHeader(){}

    public FileHeader(
            int magic,
            int version,
            long dbid) {
        this.magic=magic;
        this.version=version;
        this.dbid=dbid;
    }

    public void serialize(OutputArchive a_, String tag) throws IOException {
        a_.startRecord(this, tag);
        a_.writeInt(magic,"magic");
        a_.writeInt(version,"version");
        a_.writeLong(dbid,"dbid");
        a_.endRecord(this,tag);
    }

    @Override
    public void deserialize(InputArchive a_, String tag) throws IOException {
        a_.startRecord(tag);
        magic=a_.readInt("magic");
        version=a_.readInt("version");
        dbid=a_.readLong("dbid");
        a_.endRecord(tag);
    }

    public int getMagic() {
        return magic;
    }
}
